//
//  HYRoleHeaderView.m
//  HaiYue
//
//  Created by skyline on 2018/1/25.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYRoleDetailHeaderView.h"
#import "HYRoleView.h"
@interface HYRoleDetailHeaderView()
@property (nonatomic, strong) HYLabel *roleIDLBL;
@property (nonatomic, strong) HYLabel *officialTipsLBL;
@property (nonatomic, strong) HYRoleView *roleView;
@property (nonatomic, strong) HYButton *downloadBtn;
@property (nonatomic, strong) HYLabel *moneyLBL;
@property (nonatomic, strong) HYLabel *timeLBL;
@property (nonatomic, strong) HYLabel *sellerLBL;
@property (nonatomic, strong) HYLabel *sellerDescptionLBL;
@end
@implementation HYRoleDetailHeaderView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.roleView.imageName = @"2";
        self.roleView.game = @"皇城传奇";
        self.roleView.area = @"区服: 14";
        self.roleView.tips = @"v15暴力战士，排名第八";
        self.roleIDLBL.text = @"小号ID: 03391929";
        self.officialTipsLBL.hidden = NO;
        self.downloadBtn.hidden = NO;
        self.moneyLBL.text = @"¥88.00";
        self.timeLBL.text = @"上架时间: 01/21 11:47";
        self.sellerDescptionLBL.text = @"该卖家很懒，未填写任何描述，请以截图为准，该卖家很懒，未填写任何描述，请以截图为准，该卖家很懒，未填写任何描述";
        [self setupLine];
        [self updateBounds];
    }
    return self;
}

- (HYLabel *)roleIDLBL
{
    if (!_roleIDLBL)
    {
        _roleIDLBL = [[HYLabel alloc] initWithText:@"小号ID:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont]];
        [self addSubview:_roleIDLBL];
        [_roleIDLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
        }];
    }
    return _roleIDLBL;
}

- (HYLabel *)officialTipsLBL
{
    if (!_officialTipsLBL)
    {
        _officialTipsLBL = [[HYLabel alloc] initWithText:@"信息通过官方审核" textColor:ORANGE_COLOR textFont:[UIFont systemFontOfSize:DefaultFont]];
        [self addSubview:_officialTipsLBL];
        [_officialTipsLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(- GAP);
        }];
    }
    return _officialTipsLBL;
}

- (HYRoleView *)roleView
{
    if (!_roleView)
    {
        _roleView = [[HYRoleView alloc] initWithHeight:GameLogoWidth];
        [self addSubview:_roleView];
        [_roleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.roleIDLBL.mas_bottom).with.offset(GAP * 2);
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.height.mas_equalTo(self.roleView.bounds.size.height);
        }];
    }
    return _roleView;
}

- (HYButton *)downloadBtn
{
    if (!_downloadBtn)
    {
        _downloadBtn = [[HYButton alloc] initWithFrame:CGRectMake(0, 0, 60, 25) title:@"下载" titleColor:THEME_COLOR];
        [_downloadBtn.titleLabel setFont:[UIFont systemFontOfSize:DefaultFont weight:UIFontWeightLight]];
        _downloadBtn.type = CCShapeLayerTypeLeftHalfEllipse;
        _downloadBtn.strokeColor = THEME_COLOR;
        _downloadBtn.fillColor = RGBA(0, 206, 206, 0.1);
        [_downloadBtn addTarget:self action:@selector(methodForDownLoadBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_downloadBtn];
        [_downloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.top.equalTo(self.roleView);
            make.size.mas_equalTo(self.downloadBtn.bounds.size);
        }];
    }
    return _downloadBtn;
}

- (HYLabel *)moneyLBL
{
    if (!_moneyLBL)
    {
        _moneyLBL = [[HYLabel alloc] initWithText:@"" textColor:ORANGE_COLOR textFont:[UIFont systemFontOfSize:TitleFont]];
        [self addSubview:_moneyLBL];
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.roleView.mas_bottom).with.offset(GAP * 2);
        }];
    }
    return _moneyLBL;
}

- (HYLabel *)timeLBL
{
    if (!_timeLBL)
    {
        _timeLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont]];
        [self addSubview:_timeLBL];
        [_timeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.moneyLBL.mas_right).with.offset(GAP);
            make.centerY.equalTo(self.moneyLBL);
        }];
    }
    return _timeLBL;
}

- (HYLabel *)sellerLBL
{
    if (!_sellerLBL)
    {
        
        NSMutableAttributedString *strAttr = [[NSMutableAttributedString alloc] initWithString:@"卖家描述 (如描述与截图有出入请以截图为准)"];
        [strAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TitleFont],NSForegroundColorAttributeName:TEXT_BLACK_COLOR} range:NSMakeRange(0, 3)];
        [strAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:TipsFont],NSForegroundColorAttributeName:TEXT_GRAY_COLOR} range:NSMakeRange(4, strAttr.length - 4)];
        _sellerLBL = [[HYLabel alloc] init];
        _sellerLBL.attributedText = strAttr;
        [self addSubview:_sellerLBL];
        [_sellerLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.moneyLBL.mas_bottom).with.offset(GAP * 3.0);
        }];
    }
    return _sellerLBL;
}

- (HYLabel *)sellerDescptionLBL
{
    if (!_sellerDescptionLBL)
    {
        _sellerDescptionLBL = [[HYLabel alloc] initWithText:@"该卖家很懒，未填写任何描述，请以截图为准" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont]];
        _sellerDescptionLBL.fixedWidth = SCREEN_WIDTH - GAP * 2;
        [self addSubview:_sellerDescptionLBL];
        [_sellerDescptionLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.sellerLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
        }];
    }
    return _sellerDescptionLBL;
}
- (void)setupLine
{
    for (int i = 0; i < 2; i++)
    {
        HYView *line = [[HYView alloc] initWithColor:LINE_COLOR];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.height.mas_equalTo(1.0);
            if (i == 0)
            {
                make.top.equalTo(self.roleIDLBL.mas_bottom).with.offset(GAP);
            }
            else
            {
                make.top.equalTo(self.roleView.mas_bottom).with.offset(GAP);
            }
        }];
        
        HYView *line2 = [[HYView alloc] initWithColor:LINE_COLOR];
        [self addSubview:line2];
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.height.mas_equalTo(GAP);
            if (i == 0)
            {
                make.top.equalTo(self.moneyLBL.mas_bottom).with.offset(GAP);
            }
            else
            {
                make.top.equalTo(self.sellerDescptionLBL.mas_bottom).with.offset(GAP);
            }
        }];
    }
}

- (void)updateBounds
{
    CGFloat height_line = 2.0;
    CGFloat height_line2 = GAP * 2.0;
    CGFloat total_gap = GAP * 9.0;
    CGFloat height_subView = self.roleIDLBL.bounds.size.height + self.roleView.bounds.size.height + self.moneyLBL.bounds.size.height + self.sellerLBL.bounds.size.height + self.sellerDescptionLBL.bounds.size.height;
    
    self.bounds = CGRectMake(0, 0, self.bounds.size.width, height_line + height_line2 + total_gap + height_subView);
    
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(self.bounds.size.height);
    }];
}

- (void)methodForDownLoadBtn
{
    
}
//- (HYLabel)
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
